﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using WebUI.Models;
using Entities;
using System.Text;
using DAL;
using WebUI.Areas.Bots.Models;

namespace WebUI.Controllers
{
    public partial class FiltersController : Controller
    {
        #region Member Variables

        readonly IFilterService _filterService;
        readonly ICSVService _csvService;
        readonly IOperationRepository _operationRepository;

        #endregion

        #region Constructor

        public FiltersController(IFilterService filterService, ICSVService csvService, IOperationRepository operationRepository)
        {
            this._filterService = filterService;
            this._csvService = csvService;
            this._operationRepository = operationRepository;
        }

        #endregion

        #region Action Methods

        #region FileTypes

        public virtual PartialViewResult FileTypesIndex()
        {
            IEnumerable<string> fileTypes = _filterService.GetFileTypes();

            return PartialView(MVC.Reports.Filters.Views._FileTypesModal, fileTypes);
        }

        [HttpPost]
        public virtual JsonResult SaveFileTypes(IEnumerable<string> SelectedTypes)
        {
            var fileTypesString = _csvService.ConstructDelimitedString(SelectedTypes);
            return Json(JsonResponseFactory.SuccessResponse(fileTypesString));
        }
        
        #endregion

        #region Hosts

        public virtual ActionResult HostsIndex()
        {
            IEnumerable<string> hosts = _filterService.GetHosts();

            return PartialView(MVC.Reports.Filters.Views._HostsModal, hosts);
        }

        [HttpPost]
        public virtual JsonResult SaveHosts(IEnumerable<string> hosts)
        {
            var hostsString = _csvService.ConstructDelimitedString(hosts);
            return Json(JsonResponseFactory.SuccessResponse(hostsString));
        }

        #endregion

        #region Policies

        public virtual ActionResult PoliciesIndex()
        {
            IEnumerable<string> policies = _filterService.GetPolicies();

            return PartialView(MVC.Reports.Filters.Views._PoliciesModal, policies);
        }

        [HttpPost]
        public virtual JsonResult SavePolicies(IEnumerable<string> policies)
        {
            var policiesString = _csvService.ConstructDelimitedString(policies);
            return Json(JsonResponseFactory.SuccessResponse(policiesString));
        }

        #endregion

        #region OperationTypes

        public virtual ActionResult OperationsIndex()
        {
            IEnumerable<Operation> operations = _operationRepository.GetAll();

            return PartialView(MVC.Reports.Filters.Views._OperationTypesModal, operations);
        }

        [HttpPost]
        public virtual JsonResult SaveOperations(IEnumerable<int> operationTypes)
        {
            var operationsString = _csvService.ConstructDelimitedString(operationTypes);
            return Json(JsonResponseFactory.SuccessResponse(operationsString));
        }

        #endregion

        #endregion
    }
}